using UnityEngine;
using UnityEngine.EventSystems;

namespace Light
{
    /// <summary>
    ///     ��Ҫ���ص��ɻ�����������ȥ
    /// </summary>
    public class OnItemDrag : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
    {
        public delegate void OnDragEndHandler(Vector2 position);

        private CanvasGroup canvasGroup; //����귽��������Ļ��һ�����

        public OnDragEndHandler OnDrayEnd;


        private void Awake()
        {
            canvasGroup = GetComponent<CanvasGroup>();
        }

        /// <summary>
        ///     ��ʼ��ק
        /// </summary>
        /// <param name="eventData"></param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void OnBeginDrag(PointerEventData eventData)
        {
            transform.position = eventData.position;
            canvasGroup.blocksRaycasts = false; //�������ߴ�͸��ǰ����
        }

        /// <summary>
        ///     ��ק��
        /// </summary>
        /// <param name="eventData"></param>
        /// <exception cref="System.NotImplementedException"></exception>
        void IDragHandler.OnDrag(PointerEventData eventData)
        {
            transform.position = eventData.position;

            Debug.Log(eventData.pointerCurrentRaycast.screenPosition);
        }

        /// <summary>
        ///     ������ק
        /// </summary>
        /// <param name="eventData"></param>
        /// <exception cref="System.NotImplementedException"></exception>
        void IEndDragHandler.OnEndDrag(PointerEventData eventData)
        {
            canvasGroup.blocksRaycasts = true;
            OnDrayEnd?.Invoke(eventData.position); //������ק����

            Destroy(this);
        }
    }
}